var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/functionalComponent/table/child/order.tsx
var order_exports = {};
__export(order_exports, {
  OrderIcon: () => OrderIcon
});
module.exports = __toCommonJS(order_exports);
var import_util = require("../util");
var import_react = require("react");
var import_common = require("../base/common");
function OrderIcon({ column: { dataIndex, sortable } }) {
  const {
    table,
    table: {
      state: { orderBy, columns }
    }
  } = (0, import_react.useContext)(import_common.TableContext);
  const orderIndex = orderBy.findIndex((o) => o[dataIndex] !== void 0);
  const [direction, setDirection] = (0, import_react.useState)(orderIndex > -1 ? orderBy[orderIndex][dataIndex] : "");
  const comStyle = {
    margin: 2,
    cursor: "pointer",
    borderLeft: "4px solid transparent",
    borderRight: "4px solid transparent"
  };
  const setOrder = (0, import_util.useRefCallback)(() => {
    const order = direction === "desc" ? "asc" : direction === "asc" ? "" : "desc";
    if (orderIndex > -1) {
      if (order) {
        orderBy[orderIndex][dataIndex] = order;
      } else {
        orderBy.splice(orderIndex, 1);
      }
    } else {
      orderBy.push({ [dataIndex]: order, local: sortable.local !== false });
    }
    const orders = [
      ...orderBy.sort(function(a, b) {
        var _a, _b;
        const [aIndex, bIndex] = [Object.keys(a)[0], Object.keys(b)[0]];
        return (((_a = columns.find((c) => c.dataIndex === aIndex)) == null ? void 0 : _a.idx) || 0) - (((_b = columns.find((c) => c.dataIndex === bIndex)) == null ? void 0 : _b.idx) || 0);
      })
    ];
    setDirection(order);
    if (sortable.local !== false) {
      table.setOrderBy(orders, sortable.callback);
    } else {
      table.setExtraParam({ orderBy: orders.filter((o) => !o.local).map(({ local, ...item }) => item) });
    }
  });
  (0, import_react.useEffect)(() => {
    return table.subscribe(({ column }) => {
      column.dataIndex === dataIndex && setOrder();
    }, "onHeaderCellClick");
  }, [dataIndex]);
  (0, import_util.useUpdateEffect)(() => {
    table.notify({ direction, dataIndex }, "onDataSort");
  }, [direction]);
  return /* @__PURE__ */ React.createElement("div", { className: "order hover-icon", style: { padding: "2px 0", display: direction ? "block" : "" } }, /* @__PURE__ */ React.createElement(
    "div",
    {
      style: {
        ...comStyle,
        borderBottom: `5px solid ${direction === "asc" ? import_util.cssVar.primaryColor : "#bfbfbf"}`
      }
    }
  ), /* @__PURE__ */ React.createElement(
    "div",
    {
      style: {
        ...comStyle,
        borderTop: `5px solid ${direction === "desc" ? import_util.cssVar.primaryColor : "#bfbfbf"}`
      }
    }
  ));
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  OrderIcon
});
